// 要求时间复杂度O(logN)

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function (nums, target) {
  let left = 0, right = nums.length
  while (left <= right) {
    let mid = Math.floor((left + right) / 2)
    console.log(left, right, mid);
    if (nums[mid] === target) {
      console.log(mid);
      return mid
    }
    if (nums[mid] > nums[left]) {
      if (target >= nums[left] && target < nums[mid]) {
        right = mid - 1;
      } else {
        left = mid + 1;
      }
    } else {
      if (target > nums[mid] && target <= nums[right]) {
        left = mid + 1;
      } else {
        right = mid - 1;
      }
    }
  }
  console.log(-1);
  return -1
};

let nums = [5, 1, 3], target = 3
search(nums, target)